package com.cts.util;

import javafx.scene.input.DataFormat;
import org.apache.tomcat.jni.Local;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @projectName: CBlog
 * @package: com.cts.util
 * @className: DateFormatUtils
 * @author: chentongsheng
 * @description: TODO
 * @date: 2023/2/23 13:07
 * @version: 1.0
 */
@Component
public class DateFormatUtils {

    /**
     * @return  获取YYYY-MM-DD日期
     */
    public LocalDate getLocalDate(){
        LocalDate localDate = LocalDateTime.now().toLocalDate();
        return localDate;
    }

    /**
     * @return  获取时间戳
     */
    public LocalTime getLocalTime(){
        LocalTime localTime = LocalDateTime.now().toLocalTime();
        return localTime;
    }

    public LocalDateTime getNow(){
        LocalDateTime now = LocalDateTime.now();
        return now;
    }

    public String LocalDateTimeToString(LocalDateTime time, String pattern){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
        String format = dateTimeFormatter.format(time);
        return format;
    }

    public String LocalDateToString(LocalDate time, String pattern){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
        String format = dateTimeFormatter.format(time);
        return format;
    }

    public LocalDateTime StringToLocalDateTime(String time, String pattern){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
        LocalDateTime localDateTime = LocalDateTime.parse(time, dateTimeFormatter);
        return localDateTime;
    }

    public LocalDate StringToLocalDate(String time, String pattern){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
        LocalDate localDate = LocalDate.parse(time, dateTimeFormatter);
        return localDate;
    }
}
